//
//  CZWelcomeViewController.swift
//  WeiBo
//
//  Created by apple on 16/6/26.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit
import SDWebImage
class CZWelcomeViewController: UIViewController {
    
    override func loadView() {
        view = bgImageView
    }

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
//        更改头像约束
        self.headImageView.snp_updateConstraints { (make) -> Void in
            make.top.equalTo(self.view).offset(100)
        }
//        动画
        UIView.animateWithDuration(3, delay: 1, usingSpringWithDamping: 0.5, initialSpringVelocity: 0, options: [], animations: { () -> Void in
            self.view.layoutIfNeeded()
            }) { (_) -> Void in
                UIView.animateWithDuration(0.25, animations: { () -> Void in
                    self.messageLabel.alpha = 1
                    }, completion: { (_) -> Void in
//                        发送通知改变根控制器
                        NSNotificationCenter.defaultCenter().postNotificationName(SwitchRootVcNoti, object: "welcome")
                
                })
        }
    
    }

    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()

    }
//设置视图
    private func setupUI(){
//        添加控件
        view.addSubview(headImageView)
        view.addSubview(messageLabel)
        headImageView.snp_makeConstraints { (make) -> Void in
            make.size.equalTo(CGSize(width: 90, height: 90))
            make.top.equalTo(view).offset(400)
            make.centerX.equalTo(view)
        }
        
        messageLabel.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(view)
            make.top.equalTo(headImageView.snp_bottom).offset(16)
        }

    }
//    懒加载控件
//    背景图片
    private lazy var bgImageView: UIImageView = UIImageView(imgName: "ad_background")
//    头像
    private lazy var headImageView: UIImageView = {
        let img = UIImageView(imgName: "avatar_default_big")
        img.layer.cornerRadius = 45
        img.layer.borderColor = ThemeColor.CGColor
        img.layer.borderWidth = 3
        img.layer.masksToBounds = true
        // 设置图片
        img.sd_setImageWithURL(NSURL(string: CZUserAccountTools.sharedTools.userAccount?.avatar_large ?? ""), placeholderImage: UIImage(named: "avatar_default_big"))
        return img
    }()
//    文字
    private lazy var messageLabel: UILabel = {
        
        let lab = UILabel()
        lab.text = "欢迎回来"
        lab.font = UIFont.systemFontOfSize(18)
        lab.textColor = UIColor.grayColor()
//        对齐方式
        lab.textAlignment = .Center
        lab.alpha = 0
        return lab
    }()

}
